import os
import sys
from dotenv import load_dotenv

def load_env():
    """加载环境变量配置"""
    if getattr(sys, 'frozen', False):
        # 打包环境
        env_path = os.path.join(sys._MEIPASS, "backend", ".env")
    else:
        # 开发环境
        env_path = os.path.join(os.path.dirname(__file__), ".env")
    
    print(f"加载环境变量文件: {env_path}")
    load_dotenv(env_path)

def is_dev_mode():
    """判断当前是否为开发模式"""
    env = os.getenv("ENV", "development").lower()
    return env in ['development', 'dev', '1']

def get_log_level():
    """获取日志级别配置"""
    if is_dev_mode():
        return "DEBUG"
    else:
        return "INFO"